import React, { Component } from 'react';
import './List.scss'
import { index_nav } from '../utils/api'
class List extends Component {
    constructor(props) {
        super(props);
        this.state = {
            arr: []
        }
    }
    //组件更新时发请求
    componentDidMount() {
        index_nav().then((res) => {
            if (res.data.code == 200) {
                console.log(res.data)
                this.setState({ arr: res.data.list })
            }
        })
    }
    render() {
        return (
            <div className='listbox'>
                {
                    this.state.arr.map((element, index) => {
                        return (
                            <div className="dv" key={index}>
                                <img src={element.pic} alt="" />
                                <p>{element.name}</p>
                            </div>
                        )
                    })
                }
            </div>
        );
    }

}

export default List;